package com.yvdelx.cyclowomen.activity.listener;

import android.content.DialogInterface;

import com.yvdelx.cyclowomen.activity.CalendarActivity;
import com.yvdelx.cyclowomen.activity.CycleChoiceDialog;
import com.yvdelx.cyclowomen.object.Cycle;
import com.yvdelx.cyclowomen.utility.LogUtility;

/**
 * Created by ydelvaux on 18/07/2014.
 * Dismiss listener to make an action then the cycle choice dialog has finished to work
 */
public class ChoiceCycleDialogListener implements DialogInterface.OnDismissListener {

    CalendarActivity activity;

    /**
     * Constructor with the calendar activity
     * @param activity CalendarActivity
     */
    public ChoiceCycleDialogListener(CalendarActivity activity){
        this.activity = activity;
    }

    @Override
    public void onDismiss(DialogInterface dialogInterface) {
        CycleChoiceDialog dialog = (CycleChoiceDialog) dialogInterface;
        // If the dialog is finished with this event, then no cycle has been choose
        if(!dialog.isOnBackSelected()) {
            Cycle cycle = dialog.getCycle();
            try{
                this.activity.displayGraphic(cycle);
            } catch(Exception ex){
                LogUtility.error(this.getClass(), ex.getMessage(), ex);
            }
        }
    }
}
